/**
 * Copyright (C) 2021 Huawei Device Co., Ltd.
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * <p>
 * http://www.apache.org/licenses/LICENSE-2.0
 * <p>
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package hollowsoft.demo.slidingdrawer.slice;

import hollowsoft.demo.slidingdrawer.ResourceTable;
import hollowsoft.slidingdrawer.SlidingDrawer;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.colors.RgbColor;
import ohos.agp.components.*;
import ohos.agp.components.element.ShapeElement;

/**
 * MainAbilitySlice class
 */
public class MainAbilitySlice extends AbilitySlice {
    private static final int CYAN = 0xFF41C7D6;

    @Override
    public void onStart(Intent intent) {
        super.onStart(intent);
        super.setUIContent(ResourceTable.Layout_ability_main);

        SlidingDrawer drawer1 = (SlidingDrawer) findComponentById(ResourceTable.Id_slide);
        drawer1.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                drawer1.animateOpen();
            }
        });

        PositionLayout drawerMain = (PositionLayout) findComponentById(ResourceTable.Id_main);
        SlidingDrawer drawer = new SlidingDrawer(this);
        drawer.setOrientation(Component.VERTICAL);
        Component viewHandle = new Component(this);
        PositionLayout.LayoutConfig drawerConfig = new DirectionalLayout.LayoutConfig(100, 200);
        viewHandle.setLayoutConfig(drawerConfig);
        drawer.setHandle(viewHandle);
        ShapeElement dynamic = new ShapeElement();
        dynamic.setRgbColor(RgbColor.fromArgbInt(CYAN));
        ShapeElement dynamic2 = new ShapeElement();
        dynamic2.setRgbColor(RgbColor.fromArgbInt(0xff00ff5e));
        viewHandle.setBackground(dynamic);
        DirectionalLayout viewContent = new DirectionalLayout(this);
        viewContent.setBackground(dynamic2);
        drawerConfig = new DirectionalLayout.LayoutConfig(ComponentContainer.LayoutConfig.MATCH_PARENT,
                700);
        viewContent.setLayoutConfig(drawerConfig);
        drawer.setHolder(viewContent);
        drawerMain.addComponent(drawer);
        viewContent.setOrientation(Component.VERTICAL);

        viewHandle.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                drawer.animateOpen();
            }
        });
    }

    @Override
    public void onActive() {
        super.onActive();
    }

    @Override
    public void onForeground(Intent intent) {
        super.onForeground(intent);
    }
}
